#include <xmlsec/xmltree.h>
#include <xmlsec/keys.h>
#include <xmlsec/keyinfo.h>

#include "charon.h"

xmlSecKeyPtr ch_key_extract(xmlNodePtr node, xmlSecKeyPtr key) {
  xmlSecKeyInfoCtxPtr keyInfo;

  if(!key)
    key = xmlSecKeyCreate();
  if(!key)
    return NULL;
  keyInfo = xmlSecKeyInfoCtxCreate(NULL);
  if(!keyInfo ||
     !xmlSecKeyInfoNodeRead(node, key, keyInfo))
    return NULL;
  xmlSecKeyInfoCtxDestroy(keyInfo);
  return key;
}
